home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Toolkit;
- import java.awt.image.ColorModel;
- import java.awt.image.ImageObserver;
- import java.awt.image.MemoryImageSource;
- import java.awt.image.PixelGrabber;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import java.net.URL;
-
- public class ImageIcon implements Icon, Serializable {
- transient Image image;
- transient int loadStatus;
- ImageObserver imageObserver;
- String description;
- protected static final Component component = new 1();
- protected static final MediaTracker tracker;
- int width;
- int height;
-
- static {
- tracker = new MediaTracker(component);
- }
-
- public ImageIcon() {
- this.loadStatus = 0;
- this.description = null;
- this.width = -1;
- this.height = -1;
- }
-
- public ImageIcon(byte[] imageData) {
- this.loadStatus = 0;
- this.description = null;
- this.width = -1;
- this.height = -1;
- this.image = Toolkit.getDefaultToolkit().createImage(imageData);
- if (this.image != null) {
- Object o = this.image.getProperty("comment", this.imageObserver);
- if (o instanceof String) {
- this.description = (String)o;
- }
-
- this.loadImage(this.image);
- }
- }
-
- public ImageIcon(byte[] imageData, String description) {
- this.loadStatus = 0;
- this.description = null;
- this.width = -1;
- this.height = -1;
- this.image = Toolkit.getDefaultToolkit().createImage(imageData);
- if (this.image != null) {
- this.description = description;
- this.loadImage(this.image);
- }
- }
-
- public ImageIcon(Image image) {
- this.loadStatus = 0;
- this.description = null;
- this.width = -1;
- this.height = -1;
- this.image = image;
- Object o = image.getProperty("comment", this.imageObserver);
- if (o instanceof String) {
- this.description = (String)o;
- }
-
- this.loadImage(image);
- }
-
- public ImageIcon(Image image, String description) {
- this(image);
- this.description = description;
- }
-
- public ImageIcon(String filename) {
- this(filename, filename);
- }
-
- public ImageIcon(String filename, String description) {
- this.loadStatus = 0;
- this.description = null;
- this.width = -1;
- this.height = -1;
- this.image = Toolkit.getDefaultToolkit().getImage(filename);
- this.description = description;
- this.loadImage(this.image);
- }
-
- public ImageIcon(URL location) {
- this(location, location.toExternalForm());
- }
-
- public ImageIcon(URL location, String description) {
- this.loadStatus = 0;
- this.description = null;
- this.width = -1;
- this.height = -1;
- this.image = Toolkit.getDefaultToolkit().getImage(location);
- this.description = description;
- this.loadImage(this.image);
- }
-
- public String getDescription() {
- return this.description;
- }
-
- public int getIconHeight() {
- return this.height;
- }
-
- public int getIconWidth() {
- return this.width;
- }
-
- public Image getImage() {
- return this.image;
- }
-
- public int getImageLoadStatus() {
- return this.loadStatus;
- }
-
- public ImageObserver getImageObserver() {
- return this.imageObserver;
- }
-
- protected void loadImage(Image image) {
- synchronized(tracker){}
-
- try {
- tracker.addImage(image, 0);
-
- try {
- tracker.waitForID(0, 5000L);
- } catch (InterruptedException var5) {
- System.out.println("INTERRUPTED while loading Image");
- }
-
- this.loadStatus = tracker.statusID(0, false);
- tracker.removeImage(image, 0);
- this.width = image.getWidth(this.imageObserver);
- this.height = image.getHeight(this.imageObserver);
- } catch (Throwable var6) {
- throw var6;
- }
-
- }
-
- public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
- if (this.imageObserver == null) {
- g.drawImage(this.image, x, y, c);
- } else {
- g.drawImage(this.image, x, y, this.imageObserver);
- }
-
- }
-
- private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
- s.defaultReadObject();
- int w = s.readInt();
- int h = s.readInt();
- int[] pixels = (int[])s.readObject();
- Toolkit tk = Toolkit.getDefaultToolkit();
- ColorModel cm = ColorModel.getRGBdefault();
- this.image = tk.createImage(new MemoryImageSource(w, h, cm, pixels, 0, w));
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public void setImage(Image image) {
- this.image = image;
- this.loadImage(image);
- }
-
- public void setImageObserver(ImageObserver observer) {
- this.imageObserver = observer;
- }
-
- private void writeObject(ObjectOutputStream s) throws IOException {
- s.defaultWriteObject();
- int w = this.getIconWidth();
- int h = this.getIconHeight();
- int[] pixels = new int[w * h];
-
- try {
- PixelGrabber pg = new PixelGrabber(this.image, 0, 0, w, h, pixels, 0, w);
- pg.grabPixels();
- if ((pg.getStatus() & 128) != 0) {
- throw new IOException("failed to load image contents");
- }
- } catch (InterruptedException var6) {
- throw new IOException("image load interrupted");
- }
-
- s.writeInt(w);
- s.writeInt(h);
- s.writeObject(pixels);
- }
- }
-